﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xinkui.Entity.AutoGenerator;
using Xinkui.Common;
using Xinkui.DataAccess.AutoGenerator;

namespace Xinkui.WebModel.Cache {
    public static class EquipmentInfoCache {

        public static EquipmentInfo_Entity Get(int companyId, int eqId) {
            var companyEquipmentInfoList = List(companyId);
            if (companyEquipmentInfoList != null) {
                return companyEquipmentInfoList.FirstOrDefault(u => u.EquipmentID == eqId);
            }
            else {
                return null;
            }
        }

        public static List<EquipmentInfo_Entity> List(int companyId) {
            return CacheProxy.Get<List<EquipmentInfo_Entity>>(SystemConst.CacheConst.GetCompanyEquipmentKey(companyId), () =>
            {
                return ListFromDb(companyId);
            });
        }

        public static List<EquipmentInfo_Entity> ListFromDb(int companyId) {

            return Singleton<EquipmentInfoDataAccess>.Instance.EquipmentInfo_ListByCompany(companyId);
        }
    }
}
